<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * 法币交易订单申诉表
 */
class Appeal extends Model
{
    protected $table = 'appeals';

    protected $fillable = [
        'id',
        'uid', //申诉人id
        'rid', //recharge表id
        'type', //类型 1 对方未放币 2 对方无应答 3 对方未付款 4 对方有欺诈行为 5 其他
        'content', //申诉内容
        'status', //0 申述中 1已回复 2申述成功 3申述失败
        'expire_time', //申述回复过期时间 3天后
        'note',
    ];

    const TYPE_ONE = 1;
    const TYPE_TWO = 2;
    const TYPE_THREE = 3;
    const TYPE_FOUR = 4;
    const TYPE_FIVE = 5;
    public static $TYPE = [
        self::TYPE_ONE => '对方未放币',
        self::TYPE_TWO => '对方无应答',
        self::TYPE_THREE => '对方未付款',
        self::TYPE_FOUR => '对方有欺诈行为',
        self::TYPE_FIVE => '其他',
    ];

    const STATUS_ZERO = 0;
    const STATUS_ONE = 1;
    const STATUS_TWO = 2;
    const STATUS_THREE = 3;
    public static $STATUS = [
        self::STATUS_ZERO => '申诉中',
        self::STATUS_ONE => '已回复',
        self::STATUS_TWO => '申诉成功',
        self::STATUS_THREE => '申诉失败',
    ];

    //关联用户
    public function user()
    {
        return $this->hasOne('App\\Models\\User', 'id', 'uid');
    }

    //关联广告交易
    public function recharge()
    {
        return $this->hasOne('App\\Models\\Recharge', 'id', 'rid');
    }

    //关联图片
    public function appeal_imgs()
    {
        return $this->hasMany('App\\Models\\AppealImg', 'aid', 'id');
    }

    //关联回复
    public function appeal_reply()
    {
        return $this->hasOne('App\\Models\\AppealReply', 'appeal_id', 'id')->orderBy('created_at', 'desc');
    }
}
